package top.jiangqiang.crawler.core.entities;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.dromara.hutool.core.io.IoUtil;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

@Getter
@Setter
@NoArgsConstructor
public class TextCrawler extends StreamCrawler {

    private byte[] bodyBytes = new byte[0];

    @Override
    public InputStream getInputStream() {
        return IoUtil.toStream(bodyBytes);
    }

    public String getContent() {
        return new String(bodyBytes, StandardCharsets.UTF_8);
    }

    public String getContent(Charset charset) {
        return new String(bodyBytes, charset);
    }
}
